#include <sys/time.h>
#include "skynet_flow.h"
#include "utils.h"

int main()
{
	data_stream<BIT_ACTV> s_input("s_input");
	data_stream<BIT_CONV> s_output("s_output");
	#ifdef HLS_CSIM
		std::string ifm_path = "../../../../blob/input.afm";
		std::string ofm_path = "../../../../blob/avgpool.cfm";
	#else
		std::string ifm_path = "../data/Raw_u8.bin";
		std::string ofm_path = "../data/Out_s16.bin";
	#endif
	unsigned ifm_size = ROWIN * COLIN * 3;
	unsigned ofm_size = 7;

	IDT* ifm = (IDT*)sds_alloc(ifm_size*N_BATCH*sizeof(IDT));
	ODT* ofm = (ODT*)sds_alloc(ofm_size*N_BATCH*sizeof(ODT));

	load_ifm_ptr<BIT_IO, N_BATCH>(ifm, ifm_path, ifm_size);
	std::cout << "load input ok" << std::endl;

	timeval start,end;
	gettimeofday(&start, NULL);
	skynet_flow(ifm, ofm);
	gettimeofday(&end, NULL);

	int32_t error_cnt = check_cfm_ptr<N_BATCH>(ofm, ofm_path, ofm_size);
	sds_free(ifm);
	sds_free(ofm);

	if(error_cnt > 0)
	{
		std::cout << "Test Failed! " << error_cnt << " errors" << std::endl;
		return 1;
	}
	else
	{
		std::cout << "Test Passed! " << std::endl;
		return 0;
	}
}
